package main

import (
	"context"
	blobpb "coolcar/proto/blob_out/v1"
	"fmt"

	"google.golang.org/grpc"
)

func main() {
	conn, err := grpc.Dial(":50091", grpc.WithInsecure())
	if err != nil {
		panic(err)
	}

	client := blobpb.NewBlobServiceClient(conn)
	c := context.Background()
	//createBlob(c, client)
	//getBlob(c, client)
	getBlobURL(c, client)
}

func createBlob(c context.Context, client blobpb.BlobServiceClient) {
	res, err := client.CreateBlob(c, &blobpb.CreateBlobRequest{
		AccountId:           "account1",
		UploadUrlTimeoutSec: 1000,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println("res ===> ", res)
}

func getBlob(c context.Context, client blobpb.BlobServiceClient) {
	res, err := client.GetBlob(c, &blobpb.GetBlobRequest{
		Id: "61b0b058dd2a896c90a42b37",
	})

	if err != nil {
		panic(err)
	}
	fmt.Printf("res ===> %+v", res)
}

func getBlobURL(c context.Context, client blobpb.BlobServiceClient) {
	res, err := client.GetBlobURL(c, &blobpb.GetBlobURLRequest{
		Id:         "61b0b058dd2a896c90a42b37",
		TimeoutSec: 20,
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("res ===> %+v", res)
}
